package com.example.backendmanage.controller;

import com.example.backendmanage.common.AjaxResult;
import com.example.backendmanage.info.UploadFile;
import com.example.backendmanage.mapper.FileMapper;
import com.example.backendmanage.mapper.FileMapper2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * 关于file数据库的增删查改
 * */
@RestController
@RequestMapping("/file")
public class FileController2 {
    @Autowired
    FileMapper2 fileMapper2;
    @RequestMapping("/load")
    public AjaxResult load(@RequestParam(defaultValue = "") String filename,
    @RequestParam(defaultValue = "") String fileType,@RequestParam Integer pageIndex,@RequestParam Integer pageSize){
        int total=0;
        Integer pageNum=(pageIndex-1)*pageSize;
        List<UploadFile> lists=fileMapper2.findFiles(filename,fileType,pageNum,pageSize);
        List<UploadFile> AllList=fileMapper2.findAllFiles();
        if (filename.equals("")&&fileType.equals("")){
            total=AllList.size();
        }else {
            total=lists.size();
        }
        HashMap<String,Object> res=new HashMap<>();
        res.put("FindValue",lists);
        res.put("total",total);
        return AjaxResult.success(res);
    }
}
